package com.prestamomo.vil.ppa.pmvilpage.pmfitter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.prestamomo.vil.ppa.PmvilApp;
import com.prestamomo.vil.ppa.R;
import com.prestamomo.vil.ppa.pmvilapi.PmvilQuestion;

import java.util.List;

public class PmvilQuestionFiter extends RecyclerView.Adapter<PmvilQuestionFiter.PmvilQuesHodle> {

    private Context pmvilConQues;
    private List<PmvilQuestion> pmvilListQues;

    public PmvilQuestionFiter(Context pmvilConQues, List<PmvilQuestion> pmvilListQues) {
        this.pmvilConQues = pmvilConQues;
        this.pmvilListQues = pmvilListQues;
    }

    @NonNull
    @Override
    public PmvilQuestionFiter.PmvilQuesHodle onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View pmvilItemView = LayoutInflater.from(pmvilConQues).inflate(R.layout.question_list_pmvil_item, parent, false);
        return new PmvilQuesHodle(pmvilItemView);
    }

    @Override
    public void onBindViewHolder(@NonNull PmvilQuestionFiter.PmvilQuesHodle holder, int position) {
            if(position==pmvilListQues.size()-1){
                holder.questiListView.setVisibility(View.GONE);
            }else {
                holder.questiListView.setVisibility(View.VISIBLE);
            }

            holder.questiListTvQuestTime.setText(pmvilListQues.get(position).getPmvilquestionTime());
            holder.questiListTvQuestStr.setText(Html.fromHtml("<font color ='#333333'>評論內容： </font>"+pmvilListQues.get(position).getPmvilquestion()));
            if(pmvilListQues.get(position).getPmvilstatus().equals("0")){
                holder.questiListTvAnwTime.setText("---");
                holder.questiListTvAnwStr.setText(Html.fromHtml("<font color ='#FE8641'>回覆內容：</font>---"));
            }else{
                holder.questiListTvAnwTime.setText(pmvilListQues.get(position).getPmvilanswerTime());
                holder.questiListTvAnwStr.setText(Html.fromHtml("<font color ='#FE8641'>回覆內容：</font>"+pmvilListQues.get(position).getPmvilanswer()));
            }
    }

    @Override
    public int getItemCount() {
        return pmvilListQues.size();
    }

    public class PmvilQuesHodle extends RecyclerView.ViewHolder{
        private View questiListView;
        private TextView questiListTvAnwTime;
        private TextView questiListTvAnwStr;
        private TextView questiListTvQuestTime;
        private TextView questiListTvQuestStr;
        public PmvilQuesHodle(@NonNull View itemView) {
            super(itemView);
            initPmvilQuesItem(itemView, PmvilApp.getPmvilApss());
        }

        private void initPmvilQuesItem(@NonNull View itemView,Context pmvilwCOnt) {
            questiListView = itemView.findViewById(R.id.quest_item_pmvil_view);
            questiListTvAnwTime = itemView.findViewById(R.id.quest_item_pmvil_tv_anwtime);
            initPmvilQstIte(itemView);
        }

        private void initPmvilQstIte(@NonNull View itemView) {
            questiListTvAnwStr = itemView.findViewById(R.id.quest_item_pmvil_anwcont);
            questiListTvQuestTime = itemView.findViewById(R.id.quest_item_pmvil_questiontime);
            questiListTvQuestStr = itemView.findViewById(R.id.quest_item_pmvil_questionstr);
        }
    }
}
